<?php
if(!session_id()) { session_start(); }
if(!isset($_SESSION['user_type'])) {
	header('Location: index.php');
}
include_once('functions/main_functions.php');
	page_head();
	$timeZone = "Asia/Singapore";
	$dateTime = new DateTime();
	$dateTimeZone = new DateTimeZone($timeZone);
?>
		<div id="main">
			<?php
			echo '
			<table>
				<tr>
					<th colspan="4">
						Your Assignments
					</th>
				</tr>
				<tr>
					<th>
						Ticket #
					</th>
					<th>
						Title
					</th>
					<th>
						Date/Time
					</th>
					<th>
						Action
					</th>
				</tr>
			';
			include_once('functions/main_functions.php');
			$contact = fetch_your_messages();
			if($contact != 0) {
				for($i=0; $i < count($contact); $i++) {
					echo '<tr>
							<td>
							' . $contact[$i]['contact_ticket_id'] . '
							</td>
							<td>
							';
							echo "<a href='inbox_reply.php?id=" . $contact[$i]['contact_ticket_id'] . "'>" . $contact[$i]['contact_ticket_title'] . "</a>";
							echo '
							</td>
							<td>
							';
							$dateTime->setTimestamp($contact[$i]['contact_ticket_update']);
							$dateTime->setTimezone($dateTimeZone);
							echo $dateTime->format("d/m/y h:m:s");
					echo '
							</td>
							<td>
							';
							echo '<a id="close-contact-button" onclick="close_contact(' . $contact[$i]['contact_ticket_id'] . '); return false;">CLOSE</a>';
							echo '
							</td>
						</tr>
					';
				}
			} else {
				echo "<tr><td colspan='3'>You do not have any assignemnts.</td></tr>";
			}
			echo '
			</table>
			<p></p>
			';
			
			//No Assignments
			echo '
			<table>
				<tr>
					<th colspan="3">
						Unassigned Tickets
					</th>
				</tr>
				<tr>
					<th>
						Ticket #
					</th>
					<th>
						Title
					</th>
					<th>
						Date/Time
					</th>
				</tr>
			';
			include_once('functions/main_functions.php');
			$contact = fetch_new_messages();
			if($contact != 0) {
				for($i=0; $i < count($contact); $i++) {
					echo '<tr>
							<td>
							' . $contact[$i]['contact_ticket_id'] . '
							</td>
							<td>
							';
							echo "<a href='inbox_reply.php?id=" . $contact[$i]['contact_ticket_id'] . "'>" . $contact[$i]['contact_ticket_title'] . "</a>";
							echo '
							</td>
							<td>
							';
							$dateTime->setTimestamp($contact[$i]['contact_ticket_update']);
							$dateTime->setTimezone($dateTimeZone);
							echo $dateTime->format("d/m/y h:m:s");
					echo '
							</td>
						</tr>
					';
				}
			} else {
				echo "<tr><td colspan='3'>There are no open requests.</td></tr>";
			}
			echo '
			</table>
			';
			?>
		</div>
<?php
	page_foot();
?>